const express = require('express');
const path = require('path');

const app = express();

app.use(express.static(path.join(__dirname + '/src')));

// 解析请求体中的参数
// 把参数解析放在req.body中
app.use(express.json(), express.urlencoded())

app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    if(req.method=="OPTIONS") {
        res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
        res.header("Access-Control-Allow-Methods","PUT,POST,GET,PATCH,DELETE,OPTIONS");
        res.sendStatus(200);
    } else{
        next();
    }
});

// 引入接口路由模块
let user = require('./api/user');
let books = require('./api/books');
let manager = require('./api/manager');
let booktype = require('./api/booktype')
let swiper = require('./api/swiper')

const { ppid } = require('process');

app.use('/user', user);
app.use('/books',books)
app.use('/manager',manager)
app.use('/booktype',booktype)
app.use('/swiper',swiper)

app.listen(4399, () => {
    console.log('server running 4399 port');
})